package com.just.gameapp.controller;

import com.just.gameapp.entity.Strategy;
import com.just.gameapp.service.StrategyService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zyr
 * @date 2024/6/18 下午3:08
 * @Description
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/strategies")
public class StrategyController {
    @Resource
    private StrategyService strategyService;
    @GetMapping("/list")
    public List<Strategy> getStrategyList() {
        return strategyService.selectStrategyList();
    }
    @PostMapping("/add")
    public String addStrategy(@ModelAttribute("strategyName") String strategyName,
                              @ModelAttribute("strategyContent") String strategyContent,
                              @ModelAttribute("gameName") String gameName,
                              @ModelAttribute("accountId") String accountId
                              ) {
        Strategy strategy = new Strategy();
        strategy.setStrategyName(strategyName);
        strategy.setStrategyContent(strategyContent);
        strategy.setGameName(gameName);
        return strategyService.saveStrategy(strategy,accountId);
    }
  @PostMapping("/delete")
  public Boolean deleteByChoice(@ModelAttribute("strategyId") String strategyId){
        log.info("strategyId:{}",strategyId);
        return strategyService.deleteByChoice(strategyId);
  }
    @PutMapping("/update")
    public Object updateStrategy(@ModelAttribute Strategy strategy) {
        return strategyService.updateById(strategy);
    }
    @PostMapping("/like")
    public List<Strategy> getStrategyByGameName(@ModelAttribute("gameName") String gameName ){
        return strategyService.getStrategyByGameName(gameName);
    }

    /**
     * 查看当前用户 对应的 所有攻略列表 id
     * @param accountId
     * @return
     */
    @GetMapping("/{accountId}")
    public List<String> getStrategyByAccountId(@PathVariable String accountId) {
        return strategyService.getStrategyByAccountId(accountId);
    }

}
